<template>
    <el-space wrap>
        <el-card class="card">

            <template #header>
                漫画阅读器
            </template>
            <el-col style="text-align: center;">
                <el-button plain @click="cartoonWatcher">阅读本地漫画</el-button>
            </el-col>
            <el-col style="margin-top: 20px;">
                <el-text type="info" size="small">该工具将修改布局，默认在新窗口打开</el-text>
            </el-col>

        </el-card>

        <el-card class="card">

            <template #header>
                电子书阅读器
            </template>
            <el-col style="text-align: center;">
                <el-button plain @click="novelWatcher">阅读本地电子书</el-button>
            </el-col>
            <el-col style="margin-top: 20px;">
                <el-text type="info" size="small">该工具将修改布局，默认在新窗口打开</el-text>
            </el-col>

        </el-card>

        <el-card class="card">

            <template #header>
                漫画转PDF工具
            </template>
            <el-col style="text-align: center;">
                <el-button plain @click="pdfConverter">PDF转化工具</el-button>
            </el-col>
            <el-col style="margin-top: 20px;">
                <el-text type="info" size="small">该工具可以将zip压缩包内的图片制成一个PDF文件，便于分享漫画~</el-text>
            </el-col>

        </el-card>

    </el-space>
</template>

<script setup lang="ts">
import { ElMessage } from 'element-plus'

const cartoonWatcher = async () => {
    const filePath = await window.electronApi.getFilePath([{ name: 'Zip', extensions: ['zip'] }])
    console.log('filePath: ' + filePath);
    if (!filePath) return;

    const info = {
        filePath: filePath,
    }

    const status = window.electronApi.cartoonWatcher(info)
    if (status) {
        ElMessage.success({
            message: "工具已启用成功",
            showClose: true,
        })
    } else {
        ElMessage.error({
            message: "工具已启用失败",
            showClose: true,
        })
    }
}

const novelWatcher = async () => {
    const filePath = await window.electronApi.getFilePath([{ name: 'Epub', extensions: ['epub'] }])
    console.log('filePath: ' + filePath);
    if (!filePath) return;

    const info = {
        filePath: filePath,
    }

    const status = window.electronApi.novelWatcher(info)
    if (status) {
        ElMessage.success({
            message: "工具已启用成功",
            showClose: true,
        })
    } else {
        ElMessage.error({
            message: "工具已启用失败",
            showClose: true,
        })
    }
}

const pdfConverter = async () => {
    const filePath = await window.electronApi.getFilePath([{ name: 'Zip', extensions: ['zip'] }])
    console.log('filePath: ' + filePath);
    if (!filePath) return;

    const info = {
        filePath: filePath,
    }

    const pdfFilePath = await window.electronApi.pdfConvert(info);
    if (pdfFilePath) {
        ElMessage.success({
            message: "转化成功，已保存在" + pdfFilePath,
            showClose: true,
        })
    } else {
        ElMessage.error({
            message: "工具已启用失败",
            showClose: true,
        })
    }
}


</script>

<style scoped>
.card {
    width: 250px;
    height: 190px;
}
</style>